package net.println.kotlin.chapter2

fun main(args: Array<String>) {
    val parent:Parent = Child()
    if(parent is Child) {
        //智能转换
        println(parent.getName())
    }

    val parent2:Parent = Parent()
    //类型转换安全as后加上?，转换失败不会crash而是返回一个null
    val child:Child? = parent2 as? Child
    println(child)

    val string:String? = "Hello"
    //若string为空，则返回空
    println(string?.length)
    //!!强制认定string不可空
    println(string!!.length)

}